package com.it2297.renderer;

import java.awt.Color;
import java.awt.Component;
import java.sql.Timestamp;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import com.it2297.main.App;
import com.it2297.model.Bid;

@SuppressWarnings("serial")
public class BiddingHistoryCellRenderer extends JLabel implements TableCellRenderer
{

	private Bid bid;

	@Override
	public Component getTableCellRendererComponent(JTable table, Object object, boolean isSelected, boolean hasFocus, int row, int column)
	{
		bid = (Bid) object;

		switch (column)
		{
			case 0:
				this.setIcon(new ImageIcon(System.getProperty("user.dir") + "/img/used-item/" + bid.getUsedItem().getUuid() + "-0-thumbnail.png"));
				this.setText("<html><body style='text-align:center'><small><strong>" + bid.getUsedItem().getTitle() + "</strong></small></body></html>");
				break;
			case 1:
				this.setIcon(null);
				this.setText("<html><body style='text-align:center'><small>" + bid.getDateBid() + "</small></html>");
				break;
			case 2:
				if (bid.getUsedItem().getWonBy() != null)
				{
					if (bid.getUsedItem().getWonBy().equals(App.currentNeedy.getNric()))
					{
						this.setText("<html><body style='text-align:center'><small><strong>" + "WON" + "</strong></small></body></html>");
					}
					else
					{
						this.setText("<html><body style='text-align:center'><small><strong>" + "LOSE" + "</strong></small></body></html>");
					}
				}
				else
				{
					this.setText("<html><body style='text-align:center'><small><strong>" + "ONGOING" + "</strong></small></body></html>");
				}

				this.setIcon(null);
				break;
		}

		if (row % 2 == 0)
		{
			this.setBackground(Color.WHITE);
		}
		else
		{
			this.setBackground(new Color(240, 240, 240));
		}
		this.setForeground(Color.BLACK);

		return this;
	}

}
